import cv2
import time
import matplotlib.pyplot as plt
from datetime import datetime

def chheck(file1,file2):
    if file1=="":
        return str(0)
    img1 = cv2.imread(file1)
    img2 = cv2.imread(file2)
    cv2.imwrite("aa0.jpg",img2)
    gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    # 二值图像
    ret, binary1 = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_TRIANGLE)
    gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    # 二值图像
    ret, binary2 = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_TRIANGLE)
    cha=abs(binary1-binary2)
    #print('sadsfsfasdf:',(cha.sum()/255))
    if (cha.sum()/255)>3000.0:
        print('change:', (cha.sum() / 255))
        return str(1)
    return str(0)

if __name__=="__main__":
    #for i in range(100):
    print(chheck('E:/INTER/image/aa'+str(129)+'.jpg','E:/INTER/image/aa'+str(133)+'.jpg'))
    x=[]
    y=[]
